/**
 * Created by EEO on 2017/6/28.
 */
(function () {
    var regExp = config.regExp;
    var $email = $('[name=email]');
    var KEY_EMAIL = 2;
    function showCheck($dom, checkInfo) {
        if (!checkInfo.result) {
            $dom.next('.help-block').show().text(checkInfo.text)
        }
        return checkInfo.result
    }
    function checkEmail() {
        var checkInfo = {
            result: true
        };
        if (!regExp.email.test($email.trimVal())) {
            checkInfo.result = false;
            checkInfo.text = '邮箱格式不正确'
        }

        if ($email.trimVal() === '') {
            checkInfo.result = false;
            checkInfo.text = '请输入邮箱'
        }
        return checkInfo
    }

    $email.on('blur', function () {
        var checkInfo = checkEmail();
        if (showCheck($(this), checkInfo)) {
        }
    });
    $('.uk-form-large').on('focus', function () {
        $(this).next('.help-block').hide();
        $('.reset-word').hide();
    })
    $('#js-submit').on('click', function () {
        if ($('.email').val() == '') {
            $('.help-block').show().text('请输入邮箱');
        }
        $.ajax({
            url: '/api/user/password/mail',
            method: 'post',
            data: {
                email: $('.email').val()
            },
            success: function (data) {
                if (data.data == null) {
                    $('.email_register').show();
                }
                if (data.status.code == '0') {
                    console.log(data.data)
                    $('.uk-form').hide();
                    $('.reset-word').show();
                    $('.email-a').text($('.email').val());
                    $('.href').attr('href', 'http://' + data.data)
                }


            }
        })


    })


}());